package com.qianfeng.missfood.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.missfood.R;
import com.qianfeng.missfood.category_bean.Category_Info;
import com.qianfeng.missfood.category_bean.Category_Second_Info;

import java.util.List;

/**
 * Created by Administrator on 2015/8/17.
 */
public class Category_Bottomgridview_adapter extends AppBaseAdapter<Category_Second_Info> {
    private List<Category_Second_Info> list;
    private BitmapUtils bitmapUtils;
    private Context context;
    public Category_Bottomgridview_adapter(List<Category_Second_Info> list, Context context) {
        super(list, context);
        this.list = list;
        this.context = context;
        bitmapUtils = new BitmapUtils(context);
        bitmapUtils.configDefaultLoadFailedImage(R.mipmap.failed);
        bitmapUtils.configDefaultLoadingImage(R.mipmap.shop_menu_moren_img);
    }


    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.category_gridview_item_layout, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        bitmapUtils.display(holder.imageView, list.get(position).getIcon());
        holder.textView.setText(list.get(position).getName());
        return convertView;
    }


    private static class ViewHolder {
        @ViewInject(R.id.gridview_image)
        private ImageView imageView;
        @ViewInject(R.id.gridview_textview)
        private TextView textView;

        public ViewHolder(View convertview) {
            ViewUtils.inject(this, convertview);
        }
    }
}
